function initCompany(){
//	厂家列表
	var companies = [];
//	key是厂家名称，value是型号名的数组
	var companyTypes = new Map();

//	key是型号名称，value是动作时间的数组
	var typeActs = new Map();
//	key是型号名称，value是持续时间的数组
	var typeConts = new Map();
//	key是型号名称，value是动作时间的平均值
	var typeActsAve = new Map();
//	key是型号名称，value是持续时间的平均值
	var typeContsAve = new Map();
//	key是厂家名称，value是动作时间的平均值
	var compActsAve = new Map();
//	key是厂家名称，value是动作时间的平均值
	var compContsAve = new Map();

	var protectChart1Data = {
			xdata:[],
			bardata:[]
	};
	var protectChart2Data = {
			xdata:[],
			bardata:[]
	};
	var faultChart1Data = {
			xdata:[],
			bardata:[]
	};
	var faultChart2Data = {
			xdata:[],
			bardata:[]
	};
	var actSelectedCompany;
	var contSelectedCompany;
	
	var ProtectChart1 = null;
	var ProtectChart2 = null;
	var FaultChart1 = null;
	var FaultChart2 = null;
	
	
	initCompanyTypes();
	function initCompanyTypes(){
		$.getJSON("/rest/protect/getProtectCompaniesTypes",function(result){
			//[[devType,devManufacturer]]
			var types = result;
			actSelectedCompany = types[0][1];
			contSelectedCompany = types[0][1];
			for(var i in types){
				var company = types[i][1];
				var type = types[i][0];

				if(companyTypes.indexOf(company) == -1){
					companies.push(company);
					companyTypes.put(company,[type]);
				}else{
					companyTypes.get(company).push(type);
				}
			}
			getActData();
			//目前没有数据，此方法在actdata里面调用
			//	getContinueData();
		});
	}
	function getActData(){
		$.getJSON("/rest/protect/getProtectActAndType",function(result){
			//[[timelag,devType]]
			var times = result;
			for(var i in times){
				var timelag = times[i][0];
				var devType = times[i][1];

				if(typeActs.indexOf(devType) == -1){
					typeActs.put(devType,[timelag]);
				}else{
					typeActs.get(devType).push(timelag);
				}
			}
			typeActs.each(function(index,key,value){
				typeActsAve.put(key,getAverage(value).toFixed(2));
			});
			initCompActsAve();
			//initProtectChart1Data();
			//initProtectChart2Data();
			getContinueData();
		});
	}
	function getContinueData(){
		//应是拿到数据。暂时使用act数据加上30
		typeActs.each(function(index,key,value){
			var val = [];
			for(var i in value){
				if(value[i] != undefined){
					val.push(value[i]+Math.random()*15+15);
				}else{
					val.push(value[i]);
				}

			}
			typeConts.put(key, val);
		});
		typeActsAve.each(function(index,key,value){
			var val = Number(value)+Math.random()*15+15;
			typeContsAve.put(key, val.toFixed(2));
		});
		initCompContsAve();
	}
	function initCompActsAve(){
		for(var i in companies){
			var company = companies[i];
			var types = companyTypes.get(company);
			var sum = 0;
			var num = 0;
			for(var j in types){
				var type = types[j];
				if(typeActsAve.get(type) != undefined){
					sum = sum + Number(typeActsAve.get(type));
					num ++;
				}
			}
			compActsAve.put(company, (sum/num).toFixed(2));
		}
	}
	function initCompContsAve(){
		for(var i in companies){
			var company = companies[i];
			var types = companyTypes.get(company);
			var sum = 0;
			var num = 0;
			for(var j in types){
				var type = types[j];
				if(typeContsAve.get(type) != undefined){
					sum = sum + Number(typeContsAve.get(type));
					num ++;
				}
			}
			compContsAve.put(company, (sum/num).toFixed(2));
		}
	}

	function initProtectChart1Data(){
		//清空数组
		protectChart1Data.xdata.splice(0,protectChart1Data.xdata.length);
		protectChart1Data.bardata.splice(0,protectChart1Data.bardata.length);

		var data = [];
		for(var i in companies){
			data.push([companies[i],compActsAve.get(companies[i])]);
		}
		data = getSort(data,1);
		for(var j in data){
			protectChart1Data.xdata.push(data[j][0]);
			protectChart1Data.bardata.push(data[j][1]);
		}
		initProtectChart1();
	}
	function initProtectChart2Data(){
		//清空数组
		protectChart2Data.xdata.splice(0,protectChart2Data.xdata.length);
		protectChart2Data.bardata.splice(0,protectChart2Data.bardata.length);

		var types = companyTypes.get(actSelectedCompany);
		var data = [];
		for(var i in types){
			data.push([types[i],typeActsAve.get(types[i])]);
		}
		data = getSort(data,1);

		for(var j in data){
			protectChart2Data.xdata.push(data[j][0]);
			protectChart2Data.bardata.push(data[j][1]);
		}
		initProtectChart2();
	}

	function initProtectChart1(){
		var bar = new CategoryBar('protectChart1');
		var xdata = protectChart1Data.xdata;
		var bardata = protectChart1Data.bardata;

		bar.setTitle("保护平均动作时间");
		bar.setxAxis(xdata);
		bar.setxAxisTitle("厂家");

		bar.setyAxis(bardata);
		bar.setyAxisName("平均动作时间");
		bar.setyAxisTitle("毫秒");
		bar.addColor('#009ad6');

		var option = bar.getOption();
		option.series[0].label.normal.formatter = function(params){
			return params.data;
		};
		bar.show();
		
		ProtectChart1 = bar.getChart();
		ProtectChart1.on('click',function(params){
			if(params.componentType == "series" 
				&& params.seriesType == "bar"){
				actSelectedCompany = params.name;
				initProtectChart2Data();
			}
		});

		return ProtectChart1;
	}
	function initProtectChart2(){
		var bar = new CategoryBar('protectChart2');
		var xdata = protectChart2Data.xdata;
		var bardata = protectChart2Data.bardata;

		bar.setTitle(actSelectedCompany);
		bar.setxAxis(xdata);
		bar.setxAxisTitle("型号");
		bar.setyAxis(bardata);
		bar.setyAxisName("平均动作时间");
		bar.setyAxisTitle("毫秒");
		bar.setDataZoom(true);
		bar.addColor("#145b7d");

		var option = bar.getOption();
		option.dataZoom[0].startValue = xdata.length > 13?xdata.length-13 : 0;
		option.dataZoom[1].startValue = xdata.length > 13?xdata.length-13 : 0;
		bar.show();
		
		ProtectChart2 = bar.getChart();
		return ProtectChart2;
	}
	
	function getAverage(array){
		if(array == undefined || array.length == 0 || array.length == undefined){
			return 0;
		}
		var result = 0;
		for(var i in array){
			result = result + array[i];
		}
		return result/array.length;
	}
//	将[[],[],]按照index的顺序从小到大排序
	function getSort(array,index){
		array.sort(compare);
		function compare(obj1,obj2){
			if(obj1 == undefined 
					|| obj1[index] == undefined 
					|| obj1[index] == null){
				return -1;
			}
			if(obj2 == undefined
					|| obj1[index] == undefined 
					|| obj1[index] == null){
				return 1;
			}
			if(Number(obj1[index]) < Number(obj2[index])){
				return -1;
			}else{
				return 1;
			}
		}
		return array;
	}
	this.resizeProtectChart = function(){
		ProtectChart1.resize();
		ProtectChart2.resize();
	};
	this.resizeFaultChart = function(){
		FaultChart1.resize();
		FaultChart2.resize();
	};
}

